#!/bin/bash
set -euo pipefail
BaseDir=$(cd "$(dirname "$0")"; pwd)
cd ${BaseDir}

#https://github.com/Tencent/CodeAnalysis.git 更新同步
rm -rf ./CodeAnalysis
git clone https://github.com/Tencent/CodeAnalysis.git

#定制替换，需要人工检查下冲突性
cp -rf ./CodeAnalysis-cust/* ./CodeAnalysis/.
mkdir -p ./CodeAnalysis/pkg
curl https://bitbucket.org/ariya/phantomjs/downloads/phantomjs-2.1.1-linux-x86_64.tar.bz2 -o ./CodeAnalysis/pkg/phantomjs.tar.bz2
pushd ./CodeAnalysis/pkg
 tar -jxvf ./phantomjs.tar.bz2
 mv ./phantomjs-2.1.1-linux-x86_64/bin/phantomjs .
popd

#构建镜像和测试运行环境
pushd CodeAnalysis
 ./tcaimage.sh
 #如上成功的话，docker-compose.yml会生成出来,并运行.
 # 完全成功后，docker-compose down清理运行，转入根目录执行 1run.sh
popd

